﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using Hidistro.ControlPanel.Promotions;
using Hidistro.Core;
using System.Web;

namespace Hidistro.UI.ControlPanel.utility
{
    public class wnxd_ProductList : WebControl
    {
        public wnxd_ProductList()
        {
            base.ID = "wnxd_ProductList";
        }
        protected override void Render(HtmlTextWriter writer)
        {
            if (this.Page.IsPostBack)
            {
                if (this.Page.Request["__EVENTTARGET"] == "wnxd_detele") PromoteHelper.DeletePromotionProducts(this.activityId, int.Parse(this.Page.Request["__EVENTARGUMENT"]));
            }
            writer.Write(this.RendHtml());
        }
        public string RendHtml()
        {
            StringBuilder sb = new StringBuilder();
            DataTable dt = PromoteHelper.GetPromotionProducts(this.activityId);
            if (dt != null && dt.Rows.Count > 0)
            {
                sb.Append("<table width=\"100%\" id=\"addlist\" cellspacing=\"0\" border=\"0\">");
                sb.Append("<tr class=\"table_title\"><th>商品名</th><th>市场价</th><th>一口价</th><th>操作</th></tr>");
                foreach (DataRow row in dt.Rows)
                {
                    sb.AppendFormat("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>", row["ProductName"], Globals.FormatMoney((decimal)row["MarketPrice"]), Globals.FormatMoney((decimal)row["SalePrice"]), string.Format("<span class=\"submit_shanchu\"><a onclick=\"return confirm('确定要执行该删除操作吗？删除后将不可以恢复！');\" href=\"javascript:__doPostBack('wnxd_detele','{0}')\">删除</a></span>", row["ProductId"]));
                }
                sb.Append("</table>");
            }
            return sb.ToString();
        }
        public int activityId { get; set; }
        public string ID
        {
            get
            {
                return base.ID;
            }
            set
            {
                base.ID = value;
            }
        }
    }
}
